package com.example.springboot_targettest;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;

import java.util.Objects;

@SuppressWarnings("unused")
public class CustomCommandLineRunner implements CommandLineRunner {
    Environment env;

    //使用构造方法的方式注入，注入Environment

    public CustomCommandLineRunner(Environment env) {
        this.env = env;
    }

    @Override
    public void run(String... arg){
        System.out.println("CommandLineRunner auto configuration");

        //利用random的RandomValuePropertySource产生一个随机的32位串
        System.out.println("Random string:".concat(Objects.requireNonNull(env.getProperty("random."))));
    }
}
